<%@page import="com.zhuoshi.dao.ManagerDao"%>
<%@page import="com.zhuoshi.utils.DESEncrypt"%>
<%@page import="com.zhuoshi.bean.ManagerBean"%>
<%@page import="com.zhuoshi.utils.Utils"%>
<%@page import="com.zhuoshi.dao.ManagerRoleDao"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	request.setCharacterEncoding("UTF-8");
	response.setContentType("text/html;charset=utf-8");
	
	ManagerRoleDao rDao = new ManagerRoleDao();
	
	String id = request.getParameter("id");//使用完毕后，在跳转页面的时候，要把这个id再给传回去，否则报null空指针
	//out.print(id);
	String username = request.getParameter("username");
	String password = request.getParameter("password");
	String realname = request.getParameter("realname");
	String gender = request.getParameter("gender");
	String role_id = request.getParameter("role_id");
	int role_type = rDao.getRoleType(Integer.parseInt(role_id));
	String telphone = request.getParameter("telphone");
	String email = request.getParameter("email");
	String area = request.getParameter("area");
	String province = request.getParameter("province");
	int enabled = 0;
	String lasttime = Utils.getNowDate();
	/* out.print("id:"+id + "<br/>");
	out.print("username:"+username + "<br/>");
	out.print("password:"+password+ "<br/>");
	out.print("realname:"+realname+ "<br/>");
	out.print("gender:"+gender+ "<br/>");
	out.print("role_id:"+role_id+ "<br/>");
	out.print("role_type:"+role_type+ "<br/>");
	out.print("telphone:"+telphone+ "<br/>");
	out.print("email:"+email+ "<br/>");
	out.print("area:"+area+ "<br/>");
	out.print("province:"+province+ "<br/>");
	out.print("enabled:"+enabled+ "<br/>");
	out.print("lasttime:"+lasttime+ "<br/>"); */
	
	
	
	ManagerBean bean1 = new ManagerBean();
	ManagerDao dao = new ManagerDao();
	ManagerBean bean = dao.getModel(Integer.parseInt(id));
	if(!password.equals(bean.getPassword())){
	
	bean1.setPassword(DESEncrypt.encryptMD5(password));
	}else{
		bean1.setPassword(password);
	}
	bean1.setId(Integer.parseInt(id));
	bean1.setUsername(username);
	if(!bean.getPassword().equals(password)){
	bean1.setPassword(DESEncrypt.encryptMD5(password));
	}
	bean1.setRealname(realname);
	bean1.setGender(gender);
	bean1.setRole_id(Integer.parseInt(role_id));
	bean1.setTelphone(telphone);
	bean1.setEmail(email);
	bean1.setArea(Integer.parseInt(area));
	bean1.setProvince(Integer.parseInt(province));
	bean1.setRole_type(role_type);
	bean1.setLasttime(bean.getLasttime());
	
	/* out.print("id:"+bean1.getId() + "<br/>");
	out.print("username:"+bean1.getUsername() + "<br/>");
	out.print("password:"+bean1.getPassword()+ "<br/>");
	out.print("realname:"+bean1.getRealname()+ "<br/>");
	out.print("gender:"+bean1.getGender()+ "<br/>");
	out.print("role_id:"+bean1.getRole_id()+ "<br/>");
	out.print("role_type:"+bean1.getRole_type()+ "<br/>");
	out.print("telphone:"+bean1.getTelphone()+ "<br/>");
	out.print("email:"+bean1.getEmail()+ "<br/>");
	out.print("area:"+bean1.getArea()+ "<br/>");
	out.print("province:"+bean1.getProvince()+ "<br/>");
	out.print("enabled:"+bean1.getEnabled()+ "<br/>");
	out.print("lasttime:"+bean1.getLasttime()+ "<br/>"); */
	
	
	
	int rows = dao.update(bean1);
	
	//out.print("[[[[[["+rows+"]]]]]]");
	
	
	if(rows>0){
		/* out.print("<script language='javascript'>alert('修改成功！');location.href='user_update.jsp?id='"+id+";</script>"); */
		out.print("<script language='javascript'>alert('修改成功！');</script>");
		out.print("<script language='javascript'>location.href='user_update.jsp?id="+id+"';</script>");
	}else{
		out.print("<script language='javascript'>alert('修改失败！');</script>");
	}
%>
